<div class="container clearfix">

	<div class="content contentAdmin">
		<div class="flow flowAdmin">

			<div class="article">
				<h3 id="id_blog_title" class="article_title" style="font-size: 1.2em;">
					{{if eq .action "add"}}新增{{else}}编辑{{end}} 博客:
				</h3>

				<div class="article_summary">
					<form method="POST" {{if eq .action "add"}}action="/admin/article/add"{{else}}action="/admin/article/{{.article.Id}}/edit"{{end}} >
					<table class="table_admin_edit">
							<tr>
								<td class="r">类别<span class="flag_required">*</span>：</td>
								<td class="l">
									<select name="article.CategoryId">
										{{$cateId := .article.CategoryId}}
										{{range $i,$v := .category}}
											<option value="{{$v.Id}}" {{if eq $v.Id $cateId}}selected="selected"{{end}}>{{$v.Name}}</option>
										{{end}}
									</select>  
									
								</td>
							</tr>

							<tr>
								<td class="r">标题<span class="flag_required">*</span>：</td>
								<td class="l">
									<input type="text" id="id_name" name="article.Title" value="{{.article.Title}}"/>	  
									
								</td>
							</tr>
							
							<tr>
								<td class="r">内容<span class="flag_required">*</span>：</td>
								<td class="l">
									<textarea id="id_content" name="article.Content" style="width:95%;height:600px;">{{.article.Content}}</textarea>
									
								</td>
							</tr>
							<tr>
								<td class="r">状态：</td>
								<td class="l">
									<select name="article.Status">
										<option value="true" {{if .article.Status}}selected="selected"{{end}}>有效</option>
										<option value="false" {{if eq .article.Status false}}selected="selected"{{end}}>无效</option>
									</select>  
								</td>
							</tr>

							<tr>
								<td class="r">标签：</td>
								<td class="l">
									<input type="text" name="article.Tags" value="{{.article.Tags}}" placeholder="多个标签请用半角逗号隔开，如：Java,C#,Go,JavaScript"/>
								</td>
							</tr>

							<tr>
								<td class="r">来源：</td>
								<td class="l">
									<input type="text" id="id_origin" name="article.Origin" value="{{.article.Origin}}" placeholder="如果转载博客请附上原地址"/>
								</td>
							</tr>
							
							
							<tr>
								<td>&nbsp;</td>
								<td>
									<input type="submit" value="提交" onclick="return checkForm()" /> 
									<a href="/admin/article/list">返回</a>
									<span id="id_msg" class="flag_required"></span>
									{{if .flashes}}
						        	<span class="msg">{{range .flashes}}{{.}}{{end}}</span>
						        	{{end}}
									<input type="hidden" name="article.Id" value="{{.article.Id}}"> 
									<input type="hidden" name="article.Read" value="{{.article.Read}}"> 
									<input type="hidden" name="article.UpCount" value="{{.article.UpCount}}">
									<input type="hidden" name="article.DownCount" value="{{.article.DownCount}}">
									<input type="hidden" name="article.Created" value="{{timeFormat .article.Created .timefmt}}"> 
									<input type="hidden" name="article.Updated" value="{{timeFormat .article.Updated .timefmt}}"> 
								</td>
							</tr>
  					</table>
				</form>
				</div>

				<script charset="utf-8" src="/static/js/plugins/kindeditor-4.1.10/kindeditor-all-min.js"></script>
				<script charset="utf-8" src="/static/js/plugins/kindeditor-4.1.10/lang/zh_CN.js"></script>

				<script type="text/javascript">

				KindEditor.ready(function(K) {              
				  window.editor = K.create("#id_content",{
					  	uploadJson : '/admin/kindeditor/upload',
					    fileManagerJson : '/admin/kindeditor/file/manager',
					    allowFileManager : true,
					    afterBlur: function(){this.sync();}
					});
				});

				  function checkForm(){
				    var id_title = $("#id_title");
				    var id_content = $("#id_content");

				    var id_origin = $("#id_origin");
				  	
				    var id_msg =  $("#id_msg");


				    id_msg.html("");

				    if(id_title.val()==""){
				      id_title.focus();
				      id_msg.html("请填写类别名称！");
				      return false;
				    }

				    if(id_content.val()==""){
				      id_content.focus();
				      id_msg.html("请填写内容名称！");
				      return false;
				    }

				    if(id_origin.val()!=""){
				    	if(!isURL2(id_origin.val())){
				    		id_content.focus();
						    id_msg.html("来源地址格式错误！");
						    return false;
				    	}			      
				    }

				    return true;
				  }

				  function isURL(str){
						var strRegex = '^((https|http|ftp|rtsp|mms)?://)' 
								+ '?(([0-9a-z_!~*\'().&=+$%-]+: )?[0-9a-z_!~*\'().&=+$%-]+@)?' //ftp的user@ 
								+ '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP形式的URL- 199.194.52.184 
								+ '|' // 允许IP和DOMAIN（域名） 
								+ '([0-9a-z_!~*\'()-]+.)*' // 域名- www. 
								+ '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' // 二级域名 
								+ '[a-z]{2,6})' // first level domain- .com or .museum 
								+ '(:[0-9]{1,4})?' // 端口- :80 
								+ '((/?)|' // a slash isn't required if there is no file name 
								+ '(/[0-9a-z_!~*\'().;?:@&=+$,%#-]+)+/?)$'; 

						var re=new RegExp(strRegex); 						
						if (re.test(str)) { 
							return true; 
						} else { 
							return false; 
						} 
				 }

				 // 建议的正则
				function isURL2(str){
				    return !!str.match(/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g);
				}

					
			</script>
			  
				
			</div>

		</div>

	</div>
	{{template "admin/sider_bar" .}}
</div>